package bsh;

import org.objectweb.asm.MethodVisitor;

import bsh.exception.CompilationFailedException;
import bsh.meta.JavaClassWrapper;
import bsh.meta.MetaTypeWrapper;
import bsh.meta.Scope;
import bsh.meta.TypeWrapper;

/**
 * Node compiler for a type literal
 * 
 * @author takeshi
 */
public class TypeLiteralNodeCompiler implements NodeCompiler {

    private final BSHType type;

    /**
     * Constructor
     * 
     * @param node the type
     */
    public TypeLiteralNodeCompiler(BSHType node) {
        this.type = node;
    }

    /**
     * {@inheritDoc}
     */
    public void compile(MethodVisitor host, CompilationState state) throws CompilationFailedException {
        TypeWrapper wrapper = TypedVariableDeclarationCompiler.resolveTypeForNode(type, state.currentScope());
        state.pushStack(new MetaTypeWrapper(wrapper));
    }

    /**
     * {@inheritDoc}
     */
    public TypeWrapper nodeResultType(Scope scope) throws CompilationFailedException {
        return JavaClassWrapper.wrapperFor(Class.class);
    }

}
